package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.EmpNormAttribute;
import com.ruoyi.system.domain.EmpNormSystem;
import com.ruoyi.system.mapper.EmpNormSystemMapper;
import com.ruoyi.system.service.IEmpNormAttributeService;
import com.ruoyi.system.service.IEmpNormSystemService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 指标体系Service业务层处理
 *
 * @author zsl
 * @date 2024-04-15
 */
@Service
public class EmpNormSystemServiceImpl extends ServiceImpl<EmpNormSystemMapper, EmpNormSystem> implements IEmpNormSystemService {

    @Autowired
    private IEmpNormAttributeService iEmpNormAttributeService;

    /**
     * 查询指标体系
     *
     * @param id 指标体系主键
     * @return 指标体系
     */
    @Override
    public EmpNormSystem selectEmpNormSystemById(Long id) {
        return this.baseMapper.selectEmpNormSystemById(id);
    }

    /**
     * 查询指标体系列表
     *
     * @param empNormSystem 指标体系
     * @return 指标体系
     */
    @Override
    public List<EmpNormSystem> selectEmpNormSystemList(EmpNormSystem empNormSystem) {
        return this.baseMapper.selectEmpNormSystemList(empNormSystem);
    }

    /**
     * 新增指标体系
     *
     * @param empNormSystem 指标体系
     * @return 结果
     */
    @Override
    public int insertEmpNormSystem(EmpNormSystem empNormSystem) {
        empNormSystem.setCreateTime(DateUtils.getNowDate());
        if (ObjectUtils.isNotEmpty(empNormSystem.getAttributeId())) {
            EmpNormAttribute attribute = iEmpNormAttributeService.selectEmpNormAttributeById(empNormSystem.getAttributeId());
            empNormSystem.setName(ObjectUtils.isNotEmpty(attribute.getName()) ? attribute.getName() : "");
        }
        return this.baseMapper.insertEmpNormSystem(empNormSystem);
    }

    /**
     * 修改指标体系
     *
     * @param empNormSystem 指标体系
     * @return 结果
     */
    @Override
    public int updateEmpNormSystem(EmpNormSystem empNormSystem) {
        empNormSystem.setUpdateTime(DateUtils.getNowDate());
        if (ObjectUtils.isNotEmpty(empNormSystem.getAttributeId())) {
            EmpNormAttribute attribute = iEmpNormAttributeService.selectEmpNormAttributeById(empNormSystem.getAttributeId());
            empNormSystem.setName(ObjectUtils.isNotEmpty(attribute.getName()) ? attribute.getName() : "");
        }
        return this.baseMapper.updateEmpNormSystem(empNormSystem);
    }

    /**
     * 批量删除指标体系
     *
     * @param ids 需要删除的指标体系主键
     * @return 结果
     */
    @Override
    public int deleteEmpNormSystemByIds(Long[] ids) {
        return this.baseMapper.deleteEmpNormSystemByIds(ids);
    }

    /**
     * 删除指标体系信息
     *
     * @param id 指标体系主键
     * @return 结果
     */
    @Override
    public int deleteEmpNormSystemById(Long id) {
        return this.baseMapper.deleteEmpNormSystemById(id);
    }

    @Override
    public EmpNormSystem selectEmpNormSystemByName(String name) {
        return this.baseMapper.selectEmpNormSystemByName(name);
    }
}
